package com.gw.mapper;

import com.gw.pojo.entity.PostSA;
import org.apache.ibatis.annotations.*;

import java.util.List;

//private static final long serialVersionUID = 1L;
//
//private int id;// 文章id
//private String title; // 文章标题
//private String content;// 文章内容
//private String author_id;// 作者id
//private int typeCode; // 文章类型, 0；活动文章;1:作品展示文章
//private String pictureUrls;//附加的图片地址
//
//private String attachmentUrls;// 附加附件的minio地址
//private LocalDateTime createTime;// 创建时间
@Mapper
public interface PostSAMapper {
    @Insert(
            "INSERT INTO posts_sa (title, content, author_id, type_code, picture_url," +
                    " attachment_url) "+
                    "VALUES (#{title}, #{content}, #{authorId}, #{typeCode}, #{pictureUrl}, #{attachmentUrl});"
    )
    void addPost(PostSA post);

    @Delete(
            "DELETE FROM posts_sa WHERE id = #{id};"
    )
    void deletePostById(Long id);

    @Select(
            "SELECT * from posts_sa;"
    )
    List<PostSA> getAllPosts();


    List<PostSA> getLatestPost(int limit);

    @Update(
            "update posts_sa " +
            "set title = #{title}, content = #{content}, author_id = #{authorId}," +
            " type_code = #{typeCode}, picture_url = #{pictureUrl}," +
            " attachment_url = #{attachmentUrl}, created_time = #{createdTime} " +
            "where id = #{id};"
    )
    void updatePost(PostSA post);

    @Select(
            "select * from posts_sa where id=#{id};"
    )
    PostSA getById(Long id);
}
